"""
@Time ： 2021/11/16 15:51
@Auth ： ChenZhangKun
"""
import unittest

from ddt import ddt, data, unpack, file_data
from selenium import webdriver
from selenium.webdriver.common.by import By

@ddt
class Cases(unittest.TestCase):
    # 前置条件
    def setUp(self) -> None:
        self.webDriver = webdriver.Chrome(r'D:\sofwares\chrom\chromedriver.exe')
        # 最大等待十秒钟
        self.webDriver.implicitly_wait(10)

    # 后置条件
    def tearDown(self) -> None:
        print("后置条件")

    # 定义测试用例
    # data的解析是按照，解析
    @data(['15723315609', 'Czk1994#'], ["15723315609", '4545'])
    @unpack
    def test_01(self, username, password):
        self.assertEqual("15723315609", username, "相等")
        self.webDriver.get("http://yancheng.bit-service.com:8082/ii/#/login")
        usernameEle = self.webDriver.find_element(By.CSS_SELECTOR, "input[name=login]")
        print(usernameEle)
        usernameEle.send_keys(username)
        passwordEle = self.webDriver.find_element(By.CSS_SELECTOR, "input[name=password]")
        print(passwordEle)
        passwordEle.send_keys(password)
        btnsEle = self.webDriver.find_elements(By.CLASS_NAME, "v-btn__content")
        for btn in btnsEle:
            print(btn.text)
            if btn.text == "登录":
                btn.click()
        # 选择是
        noEle = self.webDriver.find_element(By.CLASS_NAME, "btn")
        print(noEle.text)
        noEle.click()

    @file_data('./user.yaml')
    def test_02(self, **kwargs):
        self.webDriver.get("http://yancheng.bit-service.com:8082/ii/#/login")
        usernameEle = self.webDriver.find_element(By.CSS_SELECTOR, "input[name=login]")
        print(usernameEle)
        usernameEle.send_keys(kwargs['username'])
        passwordEle = self.webDriver.find_element(By.CSS_SELECTOR, "input[name=password]")
        print(passwordEle)
        passwordEle.send_keys(kwargs['password'])
        btnsEle = self.webDriver.find_elements(By.CLASS_NAME, "v-btn__content")
        for btn in btnsEle:
            print(btn.text)
            if btn.text == "登录":
                btn.click()
        # 选择是
        noEle = self.webDriver.find_element(By.CLASS_NAME, "btn")
        print(noEle.text)
        noEle.click()

    def test_03(self):
        print("测试用例3")


if __name__ == '__main__':
    unittest.main()
